﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Common
{
    public class PushHelper
    {
        /// <summary>
        /// pushServer 返回的结果
        /// </summary>
        public class PushResult
        {
            public int status { get; set; }
            public string msg { get; set; }
            public object data { get; set; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="url"></param>
        /// <param name="appName"></param>
        /// <param name="androidList"></param>
        /// <param name="iosList"></param>
        /// <param name="notgooglelist"></param>
        /// <param name="message"></param>
        /// <param name="data">必须是json格式,否则服务器中不能提交</param>
        /// <returns></returns>
        public static bool SendPush(string url, string appName, string androidList, string iosList, string notgooglelist, string message, string data)
        {
            if (string.IsNullOrEmpty(url))
            {
                url = "http://demo.comm01.com/pushmanager/message/add";
            }
            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("appName", appName);//唯一识别的东西

            para.Add("GoogleList", androidList);
            para.Add("IosList", iosList);
            para.Add("notgooglelist", notgooglelist);

            para.Add("Message", message);
            para.Add("data", data);

            var str = ApiHelper.SendPost(url, para);
            var result = JsonConvert.DeserializeObject<PushResult>(str);
            if (result == null)
            {
                throw new Exception("推送服务器异常");
            }
            if (result != null && result.status == 100)
            {
                return true;
            }
            throw new Exception("推送失败" + result.msg);
        }
    }
}
